package com.appkubes.mall.restful.application.user.user.service.impl;

import com.appkubes.mall.core.entity.MallUserWxApp;
import com.appkubes.mall.core.service.impl.BaseMallUserWxAppServiceImpl;
import com.appkubes.mall.restful.application.user.user.dao.UserWxAppDao;
import com.appkubes.mall.restful.application.user.user.entity.vo.ModifyUserVo;
import com.appkubes.mall.restful.application.user.user.service.UserWxAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserWxAppServiceImpl extends BaseMallUserWxAppServiceImpl implements UserWxAppService {
    @Autowired
    UserWxAppDao userWxAppDao;

    @Override
    public MallUserWxApp findByBindKey(String key) {
        MallUserWxApp query = new MallUserWxApp();
        query.setBindUserKey(key);

        List<MallUserWxApp> mallUserWxAppList = this.selectListByEntity(query);
        if (mallUserWxAppList.size() == 0) return null;
        return mallUserWxAppList.get(0);
    }

    @Override
    public Boolean modifyUserInfo(ModifyUserVo modifyUserVo) {
        MallUserWxApp mallUserWxApp = findByBindKey(modifyUserVo.getUserKey());
        if (mallUserWxApp == null) return false;
        mallUserWxApp.setAvatarUrl(modifyUserVo.getAvatarUrl());
        mallUserWxApp.setNickName(modifyUserVo.getNickName());
        return this.updateById(mallUserWxApp);
    }
}
